<template>
  <div class="item-config">

        <el-button
          type="primary"
          :loading="testLoading"
          :disabled="btnEnable"
          size="small"
          @click="startTestConfig"
          >{{ $t('custom.connector.syncAuthorization') }}</el-button
        >

  </div>
</template>

<script>
import { Component } from './modules/Component.js'
import Trail from '@/components/storybook/mixins/trail'

import { useMsal } from '@/components/storybook/hooks/useMsal'
const { getUserAuthorization } = useMsal()

export default {
  mixins: [Trail],

  props: {
    teamsConfigForm: {
      type: Object,
      default: () => {
        return {}
      }
    }
  },
  computed: {
    btnEnable () {
      return this.botAuth()
    }

  },
  data () {
    return {
      testLoading: false,
      submitEnable: true,
      isSurperAdmin: false
    }
  },
  created () {

  },
  methods: {
    botAuth () {
      let auth = false
      if (sessionStorage.getItem('isSwitchTenant') === '1') {
        auth = true
      }
      if (sessionStorage.getItem('loginAsRoleId')) {
        auth = true
      }
      if (sessionStorage.getItem('loginAsUserId')) {
        auth = true
      }
      if (this.$store.state.user.tenantCode === '1001') {
        auth = true
      }
      return auth
    },
    startTestConfig () {
      getUserAuthorization(this.$store.state.user.tenantCode, this.$store.state.user.id, this.teamsConfigForm.scope)
    },
    validateConfigForm () {
      return this.$refs['teams'].validate()
    },
    synctdData (itemInfo) {
      if (this.botAuth()) {
        return this.$message.warning(this.$t('prompt.nopermission'))
      }
      const params = {
        tenantId: this.$store.state.user.tenantCode,
        subjectCode: 'TEAMS',
        manualSyncPhoto: true
      }
      this.$interface.taskManager.syncClientData(params).then(({ data: res }) => {
        if (res.data.sync && res.data.sync.status && res.data.sync.status !== 'Success') {
          return this.$message.error(res.data.sync.errorMsg ? res.data.sync.errorMsg : res.msg)
        }

        if (itemInfo && res.data && res.data.sync) {
          itemInfo.sync.lastTime = res.data.sync.lastTime
          itemInfo.sync.status = res.data.sync.status
        }
        Component.$emit('getConnectorConfig')
        return this.$message.success(res.msg)
      }).catch(() => {
      })
    },
    detail () {

    }
  }
}
</script>

<style scoped></style>
